﻿using System.Collections.Generic;
using UnityEngine;

namespace Snake.Gameplay
{
    /// <summary>
    /// 属性
    /// </summary>
    public class GameplayAttributeData
    {
        /// <summary>
        /// 属性基础值
        /// </summary>
        public float BaseValue;

        /// <summary>
        /// 属性当前值
        /// </summary>
        public float CurrentValue;

        private readonly List<GameplayEffectModifier> _modifiers = new List<GameplayEffectModifier>();

        public void AddModifier(GameplayEffectModifier modifier)
        {
            _modifiers.Add(modifier);
            Calculate();
        }

        public void RemoveModifier(GameplayEffectModifier modifier)
        {
            _modifiers.Remove(modifier);
            Calculate();
        }

        private void Calculate()
        {
            CurrentValue = BaseValue;
            foreach (var modifier in _modifiers)
            {
                modifier.Calculate(this);
            }
        }

        private float _value;

        public virtual float Value
        {
            get => _value;
            set => _value = Mathf.Clamp(value, MinValue, MaxValue);
        }

        public virtual float MinValue { get; set; } = 0f;
        public virtual float MaxValue { get; set; } = float.MaxValue;
    }
}